package com.ssy.lingxi.product.common.enums;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 商品运费方式
 * @author jw.chen
 * @version 2.0.0
 * @date 2022/3/29
 */
public enum CarriageTypeEnum {
    Seller(1, "卖家承担运费（默认）"),
    Buyer(2, "买家承担运费");

    private Integer code;
    private String name;

    CarriageTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return LanguageHolder.getName(this.getDeclaringClass(), this.getCode());
    }

    public static String getNameByCode(Integer code) {
        CarriageTypeEnum typeEnum = Arrays.stream(CarriageTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return typeEnum == null ? "" : typeEnum.getName();
    }
}
